package com.dkm.biz.ou.repository.impl;

import com.dkm.base.api.model.Page;
import com.dkm.base.core.helper.SpringHelper;
import com.dkm.base.db.persistence.dao.IQueryDao;
import com.dkm.biz.ou.domain.Shop;
import com.dkm.biz.ou.persistence.dao.ShopQueryDao;
import com.dkm.biz.ou.persistence.entity.ShopPo;
import com.dkm.biz.ou.repository.ShopRepository;
import com.dkm.biz.repository.AbstractRepository;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 对象功能:t_ou_shop Repository接口的实现类
 * 开发公司:dkm.com
 * 开发人员:ZHH
 * 创建时间:2017-07-25 10:55:07
 */
@Repository
public class ShopRepositoryImpl extends AbstractRepository<String, ShopPo,Shop> implements ShopRepository{
	  
	@Resource
	private  ShopQueryDao shopQueryDao;

	public Shop newInstance() {
		ShopPo po = new ShopPo();
		Shop shop = SpringHelper.getBean(Shop.class);
		shop.setData(po);
		return shop;
	}

	public Shop newInstance(ShopPo po) {
		Shop shop = SpringHelper.getBean(Shop.class);
		shop.setData(po);
		return shop;
	} 
	
	@Override
	protected IQueryDao<String, ShopPo> getQueryDao() {
		return shopQueryDao;
	}

	@Override
	public List<ShopPo> findByCartShopByUserId(String zmzUserId, Page page) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("zmzUserId", zmzUserId);
		return shopQueryDao.findByKey("findByCartShopByUserId", params,page);
	}

	@Override
	public List<ShopPo> findByShopByCartItemIds(String carItemIds) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("carItemIds", carItemIds);
		return shopQueryDao.findByKey("findByShopByCartItemIds", params);
	}

	@Override
	public List<ShopPo> findShopRec() {
		Map<String, Object> params = new HashMap<String, Object>();
		return shopQueryDao.findByKey("findShopRec", params);
	}

	@Override
	public List<ShopPo> findNearbyShops(Double lon, Double lat, Integer distance, Page page) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("lon", lon);
		params.put("lat", lat);
		params.put("distance", distance);
		Integer start = (page.getPageNo() - 1) * page.getPageSize();
		Integer num = page.getPageSize();
		params.put("start", start);
		params.put("num", num);
		return shopQueryDao.findByKey("findNearbyShops", params);
	}

	@Override
	public Integer countNearbyShops(Double lon, Double lat, Integer distance) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("lon", lon);
		params.put("lat", lat);
		params.put("distance", distance);
		return shopQueryDao.countByKey("countNearbyShops", params);
	}

}
